<?php


namespace app\api\library\order\orderNum;


use app\api\model\MallOrder;
use think\facade\Db;

class V
{
    public static function run($param)
    {
        $userId = _checkEmptyParam($param[ 'userId' ], '用户ID不能为空');
        $where = [
            ['user_id', '=', $userId],
        ];
        $collageIds = Db::name('mall_order')
            ->where($where)
            ->column('collage_id');
        $collageIds = Db::name('mall_collage')
            ->where([['collage_id', 'in', $collageIds], ['finish_time', '>', 0]])
            ->column('collage_id');
        $where[]    = ['collage_id', 'in', $collageIds];
        $res    = [
            'deliveryNum' => MallOrder::where([['user_id', '=', $userId], ['order_status', '=', 30]])->count() ?? 0,
            'transNum'    => MallOrder::where([['user_id', '=', $userId], ['order_status', '=', 50]])->count() ?? 0,
            'confirmNum'  => MallOrder::where([['user_id', '=', $userId], ['order_status', '=', 60]])->count() ?? 0,
            'refundNum'   => MallOrder::where([['user_id', '=', $userId], ['order_status', '=', 70],['collage_id', 'in', $collageIds]])->count() ?? 0,
        ];
        _outPut(200, $res);
    }
}